const app = getApp()
var db = wx.cloud.database()
const _ = db.command;
var resdict = []

Page({
  data: {
    score_color:'',
    show_score:'',
    true_score:'',
    // face_data:app.globalData.face_data,
    face_res:[],
    face_data:[],
    face_img:''
  },

  onLoad() {
    
    // db.collection('face-res').doc()
    console.log("全局",app.globalData.current_result)
    var getdata = app.globalData.current_result
    var getimg = app.globalData.current_img
    var val_1 = getdata["acne"].value
    var val_2 = getdata["eye_pouch"].value
    var val_3 = getdata["skin_spot"].value
    var val_4 = getdata["blackhead"].value
    var val_5 = getdata["crows_feet"].value
    var val_6 = getdata["dark_circle"].value
    var val_7 = getdata["forehead_wrinkle"].value
    var val_8 = getdata["nasolabial_fold"].value
    var edata = [
      {"name":"粉刺","confidence":getdata["acne"].confidence,"value":getdata["acne"].value},
      {"name":"眼袋","confidence":getdata["eye_pouch"].confidence,"value":getdata["eye_pouch"].value},
      {"name":"斑点","confidence":getdata["skin_spot"].confidence,"value":getdata["skin_spot"].value},
      {"name":"黑头","confidence":getdata["blackhead"].confidence,"value":getdata["blackhead"].value},
      {"name":"鱼尾纹","confidence":getdata["crows_feet"].confidence,"value":getdata["crows_feet"].value},
      {"name":"黑眼圈","confidence":getdata["dark_circle"].confidence,"value":getdata["dark_circle"].value},
      {"name":"抬头纹","confidence":getdata["forehead_wrinkle"].confidence,"value":getdata["forehead_wrinkle"].value},
      {"name":"法令纹","confidence":getdata["nasolabial_fold"].confidence,"value":getdata["nasolabial_fold"].value},
    ]

    

    var num = 0
    for(var i = 0;i<edata.length;i++){
      var that = this
      
      if(edata[i].value<1){
        num++
        that.setData({
          true_score:num
        })
      }
      console.log('多少',num)
      console.log('多少',this.data.true_score)
    }
    
      
    this.setData({
      show_score:this.data.true_score * 10+20,
      face_data:edata,
      face_img:getimg
    })
    
    if(that.data.show_score<40){
      that.setData({
        score_color:'rgba(236, 119, 103, 0.932)'
      })
    }
    if(40<that.data.show_score<60){
      that.setData({
        score_color:'rgb(243, 245, 151)'
      })
    }
    if(60<that.data.show_score){
      that.setData({
        score_color:'lightgreen'
      })
    }

    console.log(edata)
    console.log(typeof(this.data.face_data))
    console.log("img",getimg)
    console.log("ww",this.data.face_img)
    console.log(val_1,val_2,val_3,val_4,val_5,val_6,val_7,val_8,)
    console.log(edata[1].value)

    
    
    // db.collection('face-res')
    //   .where({_id:_.exists(true)})
    //   .limit(1)
    //   .get()
    //   .then(res=>{
    //     console.log("database",res.data)
    //   })
    //   .catch(err=>{
    //     console.log(err)
    //   })      
  },
})